home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / sources / misc / volume6 / yahp2ps / part03 < prev    next >
Encoding:
Internet Message Format  |  1989-02-03  |  22.9 KB

  1. Path: xanth!nic.MR.NET!csd4.milw.wisc.edu!leah!itsgw!steinmetz!uunet!allbery
  2. From: allbery@uunet.UU.NET (Brandon S. Allbery - comp.sources.misc)
  3. Newsgroups: comp.sources.misc
  4. Subject: v06i005: HPGL to PostScript converter (Part 3 of 6)
  5. Message-ID: <46901@uunet.UU.NET>
  6. Date: 21 Jan 89 20:30:14 GMT
  7. Sender: allbery@uunet.UU.NET
  8. Reply-To: federico@actisb.UUCP (Federico Heinz)
  9. Organization: ACTIS in Berlin GmbH, W. Germany
  10. Lines: 878
  11. Approved: allbery@uunet.UU.NET (Brandon S. Allbery - comp.sources.misc)
  12.  
  13. Posting-number: Volume 6, Issue 5
  14. Submitted-by: federico@actisb.UUCP (Federico Heinz)
  15. Archive-name: yahp2ps/part03
  16.  
  17. #! /bin/sh
  18. # This is a shell archive.  Remove anything before this line, then unpack
  19. # it by saving it into a file and typing "sh file".  To overwrite existing
  20. # files, type "sh file -c".  You can also feed this as standard input via
  21. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  22. # will see the following message at the end:
  23. #        "End of archive 3 (of 6)."
  24. # Contents:  basic.c dispatch.h penctrl.h shade.c
  25. # Wrapped by federico@actisb on Wed Jan  4 13:34:47 1989
  26. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  27. if test -f 'basic.c' -a "${1}" != "-c" ; then 
  28.   echo shar: Will not clobber existing file \"'basic.c'\"
  29. else
  30. echo shar: Extracting \"'basic.c'\" \(4204 characters\)
  31. sed "s/^X//" >'basic.c' <<'END_OF_FILE'
  32. X/*
  33. X        HPGL to PostScript converter
  34. X   Copyright (C) 1988 (and following) Federico Heinz
  35. X
  36. Xyahp2ps is distributed in the hope that it will be useful, but WITHOUT ANY
  37. XWARRANTY.  No author or distributor accepts responsibility to anyone
  38. Xfor the consequences of using it or for whether it serves any
  39. Xparticular purpose or works at all, unless he says so in writing.
  40. XRefer to the Free Software Foundation's General Public License for full details.
  41. X
  42. XEveryone is granted permission to copy, modify and redistribute yahp2ps,
  43. Xbut only under the conditions described in the GNU General Public
  44. XLicense.  A copy of this license is supposed to have been given to you
  45. Xalong with yahp2ps so you can know your rights and responsibilities.  It
  46. Xshould be in a file named COPYING.  Among other things, the copyright
  47. Xnotice and this notice must be preserved on all copies.
  48. X
  49. XIn other words, go ahead and share yahp2ps, but don't try to stop
  50. Xanyone else from sharing it farther.  Help stamp out software hoarding!
  51. X
  52. Xyahp2ps is TOTALLY unrelated to GNU or the Free Software Foundation,
  53. Xit is only released under the same conditions.
  54. X
  55. X    For bug reports, wishes, etc. send e-mail to
  56. X
  57. X    ...!mcvax!unido!tub!actisb!federico  (from Europe)
  58. X    ...!uunet!pyramid!actisb!federico    (from anywhere else)
  59. X
  60. X    For Physical mail:
  61. X
  62. X    Federico Heinz
  63. X    Beusselstr. 21
  64. X    1000 Berlin 21
  65. X
  66. X    Tel. (+49 30) 396 77 92
  67. X
  68. X*/
  69. X/***********************************************************************
  70. X
  71. X  Basical pen movement.
  72. X
  73. X***********************************************************************/
  74. X
  75. X#include <ctype.h>
  76. X#include "defs.h"
  77. X#include "penctrl.h"
  78. X#include "io.h"
  79. X#include "dispatch.h"
  80. X#include "basic.h"
  81. X
  82. X
  83. Xstatic Boolean     RelativePlot;         /* Are we plotting relative points? */
  84. Xstatic char        SymbolChar;           /* Plot chars at end of vectors?    */
  85. X
  86. X
  87. X/*
  88. X
  89. X  Reset this module's private status.
  90. X
  91. X*/
  92. X
  93. Xvoid basicInit()
  94. X
  95. X{ RelativePlot = False;
  96. X  setDash(FullLine, P1P2Diagonal / 25);
  97. X  SymbolChar = '\0';
  98. X}
  99. X
  100. X
  101. X
  102. X/*
  103. X
  104. X  Follow a Polyline given as CoordinatePairs.
  105. X
  106. X*/
  107. X
  108. Xstatic void followPolyLine()
  109. X
  110. X{ CoordinatePair target;
  111. X
  112. X  while (isNumeric(LookAhead))
  113. X  { if (!getCoordinatePair(target))
  114. X    { endCommand();
  115. X      return;
  116. X    }
  117. X    if (RelativePlot)
  118. X    { target[X] = PenPosition[X] + target[X];
  119. X      target[Y] = PenPosition[Y] + target[Y];
  120. X    }
  121. X    doLine(target[X], target[Y]);
  122. X    if (SymbolChar)
  123. X      /* symbol mode stuff here */ ;
  124. X  }
  125. X  if (isTerminator(LookAhead))
  126. X    endCommand();
  127. X}
  128. X
  129. X
  130. X/***********************************************************************
  131. X
  132. X  User-controlled pen lifting, lowering and selecting.
  133. X  
  134. X***********************************************************************/
  135. X
  136. X
  137. X/*
  138. X
  139. X  Select a new pen.
  140. X
  141. X*/
  142. X
  143. XCommandImplementation selectPen()
  144. X
  145. X{ Number pen;
  146. X
  147. X  if (isNumeric(LookAhead) && getNumber(&pen))
  148. X    changePen(pen);
  149. X  else
  150. X    changePen(Zero);
  151. X  endCommand();
  152. X}
  153. X
  154. X
  155. X
  156. X/*
  157. X
  158. X  Lift the pen and follow the CoordinatePair list.
  159. X
  160. X*/
  161. X
  162. XCommandImplementation penUp()
  163. X
  164. X{ liftPen();
  165. X  followPolyLine();
  166. X}
  167. X
  168. X
  169. X
  170. X/*
  171. X
  172. X  Lower the pen and follow the CoordinatePair list.
  173. X
  174. X*/
  175. X
  176. XCommandImplementation penDown()
  177. X
  178. X{ lowerPen();
  179. X  followPolyLine();
  180. X}
  181. X
  182. X
  183. X
  184. X/************************************************************************
  185. X
  186. X     Mode switching (absolute/relative, symbol/no symbol)
  187. X  
  188. X************************************************************************/
  189. X
  190. X
  191. X
  192. X/*
  193. X
  194. X  Handle symbol mode switching.
  195. X
  196. X*/
  197. X
  198. XCommandImplementation setSymbolMode()
  199. X
  200. X{ SymbolChar = isTerminator(LookAhead) ? '\0' : getChar();
  201. X  endCommand();
  202. X}
  203. X  
  204. X
  205. X
  206. X/*
  207. X
  208. X  Start plotting with absolute coordinates.
  209. X
  210. X*/
  211. X
  212. XCommandImplementation setAbsolutePlot()
  213. X
  214. X{ RelativePlot = False;
  215. X  followPolyLine();
  216. X}
  217. X
  218. X
  219. X
  220. X/*
  221. X
  222. X  Start plotting with relative coordinate 
  223. X
  224. X*/
  225. X
  226. XCommandImplementation setRelativePlot()
  227. X
  228. X{ RelativePlot = True;
  229. X  followPolyLine();
  230. X}
  231. X
  232. X
  233. X
  234. X
  235. X/*
  236. X
  237. X  Change the line type.
  238. X
  239. X*/
  240. X
  241. XCommandImplementation setLineType()
  242. X
  243. X{ Number pattern, patternLength;
  244. X
  245. X  if (isTerminator(LookAhead))
  246. X    setDash(FullLine, DefaultPatternLength);
  247. X  else if (getInteger(&pattern))
  248. X    if (isTerminator(LookAhead))
  249. X      setDash(pattern, DefaultPatternLength);
  250. X    else if (getInteger(&patternLength))
  251. X      setDash(pattern, patternLength);
  252. X  endCommand();
  253. X}
  254. X
  255. END_OF_FILE
  256. if test 4204 -ne `wc -c <'basic.c'`; then
  257.     echo shar: \"'basic.c'\" unpacked with wrong size!
  258. fi
  259. # end of 'basic.c'
  260. fi
  261. if test -f 'dispatch.h' -a "${1}" != "-c" ; then 
  262.   echo shar: Will not clobber existing file \"'dispatch.h'\"
  263. else
  264. echo shar: Extracting \"'dispatch.h'\" \(5800 characters\)
  265. sed "s/^X//" >'dispatch.h' <<'END_OF_FILE'
  266. X/*
  267. X        HPGL to PostScript converter
  268. X   Copyright (C) 1988 (and following) Federico Heinz
  269. X
  270. Xyahp2ps is distributed in the hope that it will be useful, but WITHOUT ANY
  271. XWARRANTY.  No author or distributor accepts responsibility to anyone
  272. Xfor the consequences of using it or for whether it serves any
  273. Xparticular purpose or works at all, unless he says so in writing.
  274. XRefer to the Free Software Foundation's General Public License for full details.
  275. X
  276. XEveryone is granted permission to copy, modify and redistribute yahp2ps,
  277. Xbut only under the conditions described in the GNU General Public
  278. XLicense.  A copy of this license is supposed to have been given to you
  279. Xalong with yahp2ps so you can know your rights and responsibilities.  It
  280. Xshould be in a file named COPYING.  Among other things, the copyright
  281. Xnotice and this notice must be preserved on all copies.
  282. X
  283. XIn other words, go ahead and share yahp2ps, but don't try to stop
  284. Xanyone else from sharing it farther.  Help stamp out software hoarding!
  285. X
  286. Xyahp2ps is TOTALLY unrelated to GNU or the Free Software Foundation,
  287. Xit is only released under the same conditions.
  288. X
  289. X    For bug reports, wishes, etc. send e-mail to
  290. X
  291. X    ...!mcvax!unido!tub!actisb!federico  (from Europe)
  292. X    ...!uunet!pyramid!actisb!federico    (from anywhere else)
  293. X
  294. X    For Physical mail:
  295. X
  296. X    Federico Heinz
  297. X    Beusselstr. 21
  298. X    1000 Berlin 21
  299. X
  300. X    Tel. (+49 30) 396 77 92
  301. X
  302. X*/
  303. X/**************************************************************************
  304. X
  305. X  Define the HPGL Command data type
  306. X
  307. X***************************************************************************/
  308. X
  309. X
  310. X#define Command int
  311. X
  312. Xextern Command getCommand();    /* Get the next Command from the in stream */
  313. X
  314. X
  315. X/* These are the valid Commands */
  316. X
  317. X#define NotImplemented          0       /* Useless functions in PostScript */
  318. X#define Interactive             1       /* Fuctions requiring Plotter-
  319. X                                           -Computer interaction */
  320. X#define ArcAbsolute             2
  321. X#define ArcRelative             3
  322. X#define SetAlternateChar        4
  323. X#define Circle                  5
  324. X#define CharacterPlot           6
  325. X#define SetStandardChar         7
  326. X#define SetDefaults             8
  327. X#define SetAbsoluteDirection    9
  328. X#define SetRelativeDirection    10
  329. X#define SetLabelTerminator      11
  330. X#define RectangleAbsolute       12
  331. X#define RectangleRelative       13
  332. X#define Wedge                   14
  333. X#define SetFillType             15
  334. X#define Initialize              16
  335. X#define InputP1P2               17
  336. X#define InputWindow             18
  337. X#define PutASCIILabel           19
  338. X#define SetLineType             20
  339. X#define SetAbsolutePlot         21
  340. X#define PenDown                 22
  341. X#define SetRelativePlot         23
  342. X#define SetPaperSize            24
  343. X#define PenUp                   25
  344. X#define ShadeRectAbsolute       26
  345. X#define RotateCoordSys          27
  346. X#define ShadeRectRelative       28
  347. X#define SelectAlternate         29
  348. X#define SetScale                30
  349. X#define SetAbsoluteCharSize     31
  350. X#define SetAbsoluteCharSlant    32
  351. X#define SetSymbolMode           33
  352. X#define SelectPen               34
  353. X#define SetRelativeCharSize     35
  354. X#define SelectStandard          36
  355. X#define SetTickLength           37
  356. X#define UserChar                38
  357. X#define ShadeWedge              39
  358. X#define XTick                   40
  359. X#define YTick                   41
  360. X#define PenThickness        42
  361. X
  362. X#define NumberOfCommands        43
  363. X
  364. X
  365. X
  366. X/***************************************************************************
  367. X
  368. X   Define the CommandImplementation type.
  369. X
  370. X***************************************************************************/
  371. X
  372. Xtypedef void CommandImplementation;
  373. X
  374. X
  375. X
  376. X/****************************************************************************
  377. X
  378. X    These functions implement each command
  379. X
  380. X****************************************************************************/
  381. X
  382. Xextern CommandImplementation notImplemented();
  383. Xextern CommandImplementation interactive();
  384. Xextern CommandImplementation arcAbsolute();
  385. Xextern CommandImplementation arcRelative();
  386. Xextern CommandImplementation setAlternateChar();
  387. Xextern CommandImplementation circle();
  388. Xextern CommandImplementation characterPlot();
  389. Xextern CommandImplementation setStandardChar();
  390. Xextern CommandImplementation setDefaults();
  391. Xextern CommandImplementation setAbsoluteDirection();
  392. Xextern CommandImplementation setRelativeDirection();
  393. Xextern CommandImplementation setLabelTerminator();
  394. Xextern CommandImplementation rectangleAbsolute();
  395. Xextern CommandImplementation rectangleRelative();
  396. Xextern CommandImplementation wedge();
  397. Xextern CommandImplementation setFillType();
  398. Xextern CommandImplementation initialize();
  399. Xextern CommandImplementation inputP1P2();
  400. Xextern CommandImplementation inputWindow();
  401. Xextern CommandImplementation putASCIILabel();
  402. Xextern CommandImplementation setLineType();
  403. Xextern CommandImplementation setAbsolutePlot();
  404. Xextern CommandImplementation penDown();
  405. Xextern CommandImplementation setRelativePlot();
  406. Xextern CommandImplementation setPaperSize();
  407. Xextern CommandImplementation penUp();
  408. Xextern CommandImplementation shadeRectAbsolute();
  409. Xextern CommandImplementation rotateCoordSys();
  410. Xextern CommandImplementation shadeRectRelative();
  411. Xextern CommandImplementation selectAlternate();
  412. Xextern CommandImplementation setScale();
  413. Xextern CommandImplementation setAbsoluteCharSize();
  414. Xextern CommandImplementation setAbsoluteCharSlant();
  415. Xextern CommandImplementation setSymbolMode();
  416. Xextern CommandImplementation selectPen();
  417. Xextern CommandImplementation setRelativeCharSize();
  418. Xextern CommandImplementation selectStandard();
  419. Xextern CommandImplementation setTickLength();
  420. Xextern CommandImplementation userChar();
  421. Xextern CommandImplementation shadeWedge();
  422. Xextern CommandImplementation xTick();
  423. Xextern CommandImplementation yTick();
  424. Xextern CommandImplementation penThickness();
  425. END_OF_FILE
  426. if test 5800 -ne `wc -c <'dispatch.h'`; then
  427.     echo shar: \"'dispatch.h'\" unpacked with wrong size!
  428. fi
  429. # end of 'dispatch.h'
  430. fi
  431. if test -f 'penctrl.h' -a "${1}" != "-c" ; then 
  432.   echo shar: Will not clobber existing file \"'penctrl.h'\"
  433. else
  434. echo shar: Extracting \"'penctrl.h'\" \(5545 characters\)
  435. sed "s/^X//" >'penctrl.h' <<'END_OF_FILE'
  436. X/*
  437. X        HPGL to PostScript converter
  438. X   Copyright (C) 1988 (and following) Federico Heinz
  439. X
  440. Xyahp2ps is distributed in the hope that it will be useful, but WITHOUT ANY
  441. XWARRANTY.  No author or distributor accepts responsibility to anyone
  442. Xfor the consequences of using it or for whether it serves any
  443. Xparticular purpose or works at all, unless he says so in writing.
  444. XRefer to the Free Software Foundation's General Public License for full details.
  445. X
  446. XEveryone is granted permission to copy, modify and redistribute yahp2ps,
  447. Xbut only under the conditions described in the GNU General Public
  448. XLicense.  A copy of this license is supposed to have been given to you
  449. Xalong with yahp2ps so you can know your rights and responsibilities.  It
  450. Xshould be in a file named COPYING.  Among other things, the copyright
  451. Xnotice and this notice must be preserved on all copies.
  452. X
  453. XIn other words, go ahead and share yahp2ps, but don't try to stop
  454. Xanyone else from sharing it farther.  Help stamp out software hoarding!
  455. X
  456. Xyahp2ps is TOTALLY unrelated to GNU or the Free Software Foundation,
  457. Xit is only released under the same conditions.
  458. X
  459. X    For bug reports, wishes, etc. send e-mail to
  460. X
  461. X    ...!mcvax!unido!tub!actisb!federico  (from Europe)
  462. X    ...!uunet!pyramid!actisb!federico    (from anywhere else)
  463. X
  464. X    For Physical mail:
  465. X
  466. X    Federico Heinz
  467. X    Beusselstr. 21
  468. X    1000 Berlin 21
  469. X
  470. X    Tel. (+49 30) 396 77 92
  471. X
  472. X*/
  473. X/**************************************************************************
  474. X
  475. X   Ideal interface to the graphics hardware.
  476. X
  477. X**************************************************************************/
  478. X
  479. X/* Paper sizes */
  480. X
  481. X#define A    0
  482. X#define A4    1
  483. X#define B    2
  484. X#define A3    3
  485. X
  486. X/* Constants for A paper */
  487. X
  488. X#define MaxXA        103650000L
  489. X#define MaxYA         79620000L
  490. X
  491. X#define InitialP1XA        2500000L
  492. X#define InitialP1YA        5960000L
  493. X#define InitialP2XA      102500000L
  494. X#define InitialP2YA       77960000L
  495. X
  496. X#define InitialP1XAR       1540000L
  497. X#define InitialP1YAR       2440000L
  498. X#define InitialP2XAR      73540000L
  499. X#define InitialP2YAR     102440000L
  500. X
  501. X
  502. X/* Constants for DIN A4 paper (Default) */
  503. X
  504. X#define MaxXA4          110400000L
  505. X#define MaxYA4           77210000L
  506. X
  507. X#define InitialP1XA4        6030000L
  508. X#define InitialP1YA4        5210000L
  509. X#define InitialP2XA4      106030000L
  510. X#define InitialP2YA4       77210000L
  511. X
  512. X#define InitialP1XA4R         00000L
  513. X#define InitialP1YA4R       6100000L
  514. X#define InitialP2XA4R      72000000L
  515. X#define InitialP2YA4R     106100000L
  516. X
  517. X
  518. X/* Constants for B paper */
  519. X
  520. X#define MaxXB        166400000L
  521. X#define MaxYB        103650000L
  522. X
  523. X#define InitialP1XB         5220000L
  524. X#define InitialP1YB         2590000L
  525. X#define InitialP2XB       157220000L
  526. X#define InitialP2YB       102590000L
  527. X
  528. X#define InitialP1XBR        2830000L
  529. X#define InitialP1YBR        9340000L
  530. X#define InitialP2XBR      102830000L
  531. X#define InitialP2YBR      161340000L
  532. X
  533. X
  534. X/* Constants for A3 paper */
  535. X
  536. X#define MaxXA3        161580000L
  537. X#define MaxYA3        110400000L
  538. X
  539. X#define InitialP1XA3        1700000L
  540. X#define InitialP1YA3        6020000L
  541. X#define InitialP2XA3      153700000L
  542. X#define InitialP2YA3      106020000L
  543. X
  544. X#define InitialP1XA3R       6070000L
  545. X#define InitialP1YA3R       7970000L
  546. X#define InitialP2XA3R     106070000L
  547. X#define InitialP2YA3R     159970000L
  548. X
  549. X
  550. X#define MaxPen    60000L
  551. X
  552. X#define FullLine 70000L
  553. X#define DefaultPatternLength 40000L
  554. X
  555. X
  556. Xextern CoordinatePair PenPosition;          /* Current pen coordinates      */
  557. Xextern CoordinatePair PlotterP1, PlotterP2; /* Pn's coords in Plotter Space */
  558. Xextern Number P1P2Diagonal;            /* Distance between P1 and P2   */
  559. X
  560. Xextern Boolean PenIsUp;         /* Is the plotting pen up?                  */
  561. Xextern Boolean UserMode;    /* Are we plotting in user coordinates?     */
  562. X
  563. X
  564. X/*
  565. X
  566. X  Convert from user to plotter coordinates
  567. X
  568. X*/
  569. X
  570. X#define PlotterUnitsFactor 40
  571. X
  572. X#define plotterXUnits(x) (UserMode ? \
  573. X                           trunc(mulNum(XScaleFactor, (x))) : \
  574. X                           trunc(x))
  575. X#define plotterYUnits(x) (UserMode ? \
  576. X                           trunc(mulNum(YScaleFactor, (x))) : \
  577. X                           trunc(x))
  578. X
  579. X#define plotterXCoord(x) (UserMode ? \
  580. X                           (trunc(mulNum(XScaleFactor, (x))) + XOrigin) : \
  581. X                           trunc(x))
  582. X#define plotterYCoord(x) (UserMode ? \
  583. X                           (trunc(mulNum(YScaleFactor, (x))) + YOrigin) : \
  584. X                           trunc(x))
  585. X
  586. X
  587. Xextern Number XScaleFactor, YScaleFactor;
  588. Xextern Number XOrigin, YOrigin;
  589. X
  590. X
  591. X/* Change the location of the scaling points */
  592. X
  593. Xextern void changeP1P2();
  594. X
  595. X
  596. X
  597. X/* Reset P1 and P2 to default values */
  598. X
  599. Xextern void resetP1P2();
  600. X
  601. X
  602. X/* Set the window to the whole plotting area */
  603. X
  604. Xextern void resetWindow();
  605. X
  606. X
  607. X/* Set the window to a new value */
  608. X
  609. Xextern void setWindow();
  610. X
  611. X
  612. X/* Reset the the pen control status to default values */
  613. X
  614. Xextern void penctrlInit();
  615. X
  616. X
  617. X/* Set the scaling parameters to reflex the current status */
  618. X
  619. Xextern void updateScaling();
  620. X
  621. X
  622. X/* Quit scaling coordinates */
  623. X
  624. Xextern void turnScalingOff();
  625. X
  626. X
  627. X
  628. X/* From now on, everything will be scaled */
  629. X
  630. Xextern void turnScalingOn();
  631. X
  632. X
  633. X
  634. X/* Rotate the coordinate system */
  635. X
  636. Xextern void rotate();
  637. X
  638. X
  639. X
  640. X/* Return coordinate system to default orientation */
  641. X
  642. Xextern void unRotate();
  643. X
  644. X
  645. X
  646. X/* Moves the pen in it's current state to the absolute coordinates
  647. X   indicated in User Space */
  648. X
  649. Xextern void doLine();
  650. X
  651. X
  652. X
  653. X/* Raises the plotting pen */
  654. X
  655. Xextern void liftPen();
  656. X
  657. X
  658. X
  659. X/* Puts plotting pen in contact with the paper */
  660. X
  661. Xextern void lowerPen();
  662. X
  663. X
  664. X
  665. X/* Get a new pen */
  666. X
  667. Xextern void changePen();
  668. X
  669. X
  670. X
  671. X/* Change the line pattern */
  672. X
  673. Xextern void setDash();
  674. END_OF_FILE
  675. if test 5545 -ne `wc -c <'penctrl.h'`; then
  676.     echo shar: \"'penctrl.h'\" unpacked with wrong size!
  677. fi
  678. # end of 'penctrl.h'
  679. fi
  680. if test -f 'shade.c' -a "${1}" != "-c" ; then 
  681.   echo shar: Will not clobber existing file \"'shade.c'\"
  682. else
  683. echo shar: Extracting \"'shade.c'\" \(4134 characters\)
  684. sed "s/^X//" >'shade.c' <<'END_OF_FILE'
  685. X/*
  686. X        HPGL to PostScript converter
  687. X   Copyright (C) 1988 (and following) Federico Heinz
  688. X
  689. Xyahp2ps is distributed in the hope that it will be useful, but WITHOUT ANY
  690. XWARRANTY.  No author or distributor accepts responsibility to anyone
  691. Xfor the consequences of using it or for whether it serves any
  692. Xparticular purpose or works at all, unless he says so in writing.
  693. XRefer to the Free Software Foundation's General Public License for full details.
  694. X
  695. XEveryone is granted permission to copy, modify and redistribute yahp2ps,
  696. Xbut only under the conditions described in the GNU General Public
  697. XLicense.  A copy of this license is supposed to have been given to you
  698. Xalong with yahp2ps so you can know your rights and responsibilities.  It
  699. Xshould be in a file named COPYING.  Among other things, the copyright
  700. Xnotice and this notice must be preserved on all copies.
  701. X
  702. XIn other words, go ahead and share yahp2ps, but don't try to stop
  703. Xanyone else from sharing it farther.  Help stamp out software hoarding!
  704. X
  705. Xyahp2ps is TOTALLY unrelated to GNU or the Free Software Foundation,
  706. Xit is only released under the same conditions.
  707. X
  708. X    For bug reports, wishes, etc. send e-mail to
  709. X
  710. X    ...!mcvax!unido!tub!actisb!federico  (from Europe)
  711. X    ...!uunet!pyramid!actisb!federico    (from anywhere else)
  712. X
  713. X    For Physical mail:
  714. X
  715. X    Federico Heinz
  716. X    Beusselstr. 21
  717. X    1000 Berlin 21
  718. X
  719. X    Tel. (+49 30) 396 77 92
  720. X
  721. X*/
  722. X/************************************************************************
  723. X
  724. X  Shaded figures.
  725. X
  726. X************************************************************************/
  727. X
  728. X
  729. X#include "defs.h"
  730. X#include "dispatch.h"
  731. X#include "mchinery.h"
  732. X#include "io.h"
  733. X#include "penctrl.h"
  734. X#include "circle.h"
  735. X#include "shade.h"
  736. X
  737. Xstatic Number FillType;            /* Kind of area filling pattern   */
  738. Xstatic Number FillSpacing;         /* Spacing betwen lines */
  739. Xstatic Number FillAngle;           /* Angle at which to draw pattern */
  740. Xstatic Number PenWidth;            /* User-set pen width */
  741. X
  742. X
  743. X/*
  744. X
  745. X  Set the default parameter values for this module.
  746. X
  747. X*/
  748. X
  749. Xvoid shadeInit()
  750. X
  751. X{ FillType = DefaultFillType;
  752. X  FillSpacing = P1P2Diagonal / 100;
  753. X  FillAngle = Zero;
  754. X  PenWidth = DefaultPenWidth;
  755. X}
  756. X
  757. X/*
  758. X
  759. X  Set the pen's width.
  760. X
  761. X*/
  762. X
  763. XCommandImplementation penThickness()
  764. X
  765. X{ Number temp;
  766. X
  767. X  if (isTerminator(LookAhead) || !getNumber(&temp))
  768. X    PenWidth = DefaultPenWidth;
  769. X  else if ((temp < MinPenWidth) || (temp > MaxPenWidth))
  770. X    warning("Illegal pen thickness.");
  771. X  else
  772. X    PenWidth = temp;
  773. X  endCommand();
  774. X}
  775. X
  776. X
  777. X/*
  778. X
  779. X  Set the area fill parameters.
  780. X
  781. X*/
  782. X
  783. XCommandImplementation setFillType()
  784. X
  785. X{ Number temp;
  786. X
  787. X  if (isTerminator(LookAhead))
  788. X    FillType = DefaultFillType;
  789. X  else if (getInteger(&FillType))
  790. X    if (!isTerminator(LookAhead) && getNumber(&temp))
  791. X    { if (!temp) FillSpacing = PenWidth * PlotterUnitsFactor;
  792. X      else if (UserMode) FillSpacing = plotterXCoord(temp);
  793. X      if (!isTerminator(LookAhead) && getInteger(&temp))
  794. X        if (!(temp % (OneSquare / 2))) FillAngle = temp;
  795. X    }
  796. X  endCommand();
  797. X}
  798. X
  799. X
  800. X
  801. X/*
  802. X
  803. X  Shade a rectangle defined in absolute coordinates.
  804. X
  805. X*/
  806. X
  807. XCommandImplementation shadeRectAbsolute()
  808. X
  809. X{ CoordinatePair corner;
  810. X
  811. X  if (getCoordinatePair(corner))
  812. X    doShadeRectangle(corner, FillType, FillSpacing, FillAngle);
  813. X  endCommand();
  814. X}
  815. X
  816. X
  817. X
  818. X/*
  819. X
  820. X  Shade a rectangle defined in relative coordinates.
  821. X
  822. X*/
  823. X
  824. XCommandImplementation shadeRectRelative()
  825. X
  826. X{ CoordinatePair corner;
  827. X
  828. X  if (getCoordinatePair(corner))
  829. X  { corner[X] = PenPosition[X] + corner[X];
  830. X    corner[Y] = PenPosition[Y] + corner[Y];
  831. X    doShadeRectangle(corner);
  832. X  }
  833. X  endCommand();
  834. X}
  835. X
  836. X
  837. X
  838. X/*
  839. X
  840. X  Shade a circle wedge.
  841. X
  842. X*/
  843. X
  844. XCommandImplementation shadeWedge()
  845. X
  846. X{ Number radius, startAngle, sweepAngle, chordAngle;
  847. X
  848. X  if (getNumber(&radius) &&
  849. X      getInteger(&startAngle) &&
  850. X      getInteger(&sweepAngle))
  851. X  { fixUpStartAndSweep(&startAngle, &sweepAngle);
  852. X    getChordAngle(&chordAngle, sweepAngle, MinimumChordForWedge);
  853. X    if (chordAngle > MaximumChordAngle)
  854. X      warning("Chord angle out of range.");
  855. X    else
  856. X      doShadeWedge(PenPosition, radius, startAngle, sweepAngle, chordAngle,
  857. X                   FillType, FillSpacing, FillAngle);
  858. X    endCommand();
  859. X  }
  860. X}
  861. X
  862. X
  863. X
  864. X
  865. X
  866. X
  867. X
  868. END_OF_FILE
  869. if test 4134 -ne `wc -c <'shade.c'`; then
  870.     echo shar: \"'shade.c'\" unpacked with wrong size!
  871. fi
  872. # end of 'shade.c'
  873. fi
  874. echo shar: End of archive 3 \(of 6\).
  875. cp /dev/null ark3isdone
  876. MISSING=""
  877. for I in 1 2 3 4 5 6 ; do
  878.     if test ! -f ark${I}isdone ; then
  879.     MISSING="${MISSING} ${I}"
  880.     fi
  881. done
  882. if test "${MISSING}" = "" ; then
  883.     echo You have unpacked all 6 archives.
  884.     rm -f ark[1-9]isdone
  885. else
  886.     echo You still need to unpack the following archives:
  887.     echo "        " ${MISSING}
  888. fi
  889. ##  End of shell archive.
  890. exit 0
  891.